import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 自动生成的调用父类的代码删除
        //super.doGet(req, resp);

//        String s = null;
//        System.out.println(s.length());

        // 这个代码是打印在 Tomcat 的控制台上
        System.out.println("hello java");
        // 这个打印是打印在响应报文上，显示到页面上
        // 就是把 hello world 字符串作为响应报文的 body 了, 浏览器就会把这个 body 显示在页面上
        resp.getWriter().write("hello java11111");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doPost");
        resp.getWriter().write("doPost111");
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doPut");
        resp.getWriter().write("doPut111");
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doDelete");
        resp.getWriter().write("doDelete111");
    }
}
